<template>
  <div class="songs">
    <div class="songs-title">{{ title }}</div>
    <div class="songs-list">
      <ul>
        <li v-for="item in lists" v-bind:key="item.id">
          <router-link :to="{path: item.path ? item.path : '/', query:{type: item.type,id:item.id} }">
            <div class="img-box">
              <img v-if="item.picUrl" :src="item.picUrl" alt="" />
            </div>
            <p  v-if="item.text">{{ item.text }}</p>
            <p v-if="item.name">{{ item.name }}</p>
          </router-link>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
export default {
  //自定义属性接收父组件的数据
  // props: ['songs'],
  props: {
    songs: {
      type: [Array, Object],
    },
  },

  // 侦听器（处理异步的逻辑）
  watch: {
    songs: {
      // 深度侦听
      deep: true,
      // 立即执行
      // immediate: true,
      // 回调函数
      handler(newVal) {
        if (newVal.length == 0 || newVal == undefined) return;
        let arr = newVal.map((item) => {
          let id = item.id;
          let title = item.title;
          let picUrl = item.artist.picUrl;
          let name = item.artist.name;
          let text = item.name;
          let path = item.path;
          let type = item.type;
          return {
            id,
            title,
            picUrl,
            name,
            text,
            path,
            type
          };
        });
        // 进行了赋值  是不是就执行了set回调函数 就重新更新页面
        this.lists = [...arr];
        this.title = arr[0].title
      },
    },
  },

  // 数据
  data() {
    return {
      // 重新记录传递过来的数据
      title: "",
      lists: [],
    };
  },
};
</script>

<style lang="less">
@import "../static/less/variable.less";
.songs {
  font-size: 16px;
  padding: @pad;
  margin-bottom: 10px;
  // background-color: #f0f0f0;
  background-image: linear-gradient(
    to bottom,
    #fff,
    #FED789,
    #fff,
  );
  min-height: 230px;
}
.songs-title {
  padding: 10px 0 10px 0;
}
.songs-list {
  width: 100%;
  ul {
    width: 100%;
    display: flex;
    overflow-x: scroll;
    li {
      width: 140px;
      flex-shrink: 0;
      margin-right: 10px;
      a {
        display: block;
        text-decoration: none;
        color: #000;
        p:nth-child(2) {
          font-size: 15px;
          padding: 4px 0;
          //css 控制文本溢出变省略号(n行)
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        p:nth-child(3) {
          color: #999;
          font-size: 13px;
          //css 控制文本溢出变省略号(1行)
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
    .img-box {
      img {
        width: 140px;
      }
    }
  }

  .img-box {
    width: 140px;
    height: 112px;
    // border: 1px solid #ccc;
    // background-color: #ccc;
    border-radius: 10px;
    overflow: hidden;
    text-align: center;
    line-height: 112px;
    img {
      vertical-align: middle;
      width: 100%;
    }
  }
}
// 移除web端的滚动条
::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
</style>